/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PanelClases.java
 *
 * Created on 11-jun-2011, 21:45:48
 */

package generadordeclasesv003.Vista;

import GeneradordeClases.Mensajes.MensajesAMostrar;
import generadordeclasesv003.Controlador.Controlador_GestorDeClases;
import generadordeclasesv003.Modelo.Clase;

import java.util.Iterator;
import javax.swing.DefaultListModel;

/**
 *
 * @author Administrador
 */
public class PanelClases extends javax.swing.JFrame {


private DefaultListModel modelo;
    /** Creates new form PanelClases */
    public PanelClases() {
        modelo=new DefaultListModel();
        initComponents();
         Lista_de_Clases_Crear.setModel(modelo);
                
    }



public void AgregarClasesExistentesAModelo(){
Iterator i=null;


    i=Controlador_GestorDeClases.getInstancia().getClasesExistentes().iterator();
while(i.hasNext()){
    Clase c=(Clase)i.next();
    if(c.isIsPrimitiva()){
    modelo.addElement(c);
    }
    
}





}

public void agregarClasesACrearAModelo(){
 Iterator j=null;
 j=Controlador_GestorDeClases.getInstancia().getClasesACrear().iterator();
 while(j.hasNext()){
    Clase c=(Clase)j.next();
     if(c.getIdentificadordeClase()==2){
     modelo.addElement(c);
    }
    
}
}







    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        Lista_de_Clases_Crear = new javax.swing.JList();
        jToolBar1 = new javax.swing.JToolBar();
        jSeparator3 = new javax.swing.JToolBar.Separator();
        jButton1 = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        jButton2 = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JToolBar.Separator();
        BotonModificarClase = new javax.swing.JButton();
        jSeparator4 = new javax.swing.JToolBar.Separator();
        jButton4 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        chec_clasesExistentes = new javax.swing.JCheckBox();
        chec_clasesAGenerar = new javax.swing.JCheckBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Buscar Clase");
        setResizable(false);

        jLabel1.setText("Nombre Clase:");

        jScrollPane1.setViewportView(Lista_de_Clases_Crear);

        jToolBar1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jToolBar1.setRollover(true);
        jToolBar1.add(jSeparator3);

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Iconos/application-next_16x16-32.gif"))); // NOI18N
        jButton1.setText("Generar Clase");
        jButton1.setBorder(null);
        jButton1.setFocusable(false);
        jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButton1);
        jToolBar1.add(jSeparator1);

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Iconos/Delete_01_16x16-32.gif"))); // NOI18N
        jButton2.setText("Elimina");
        jButton2.setBorder(null);
        jButton2.setFocusable(false);
        jButton2.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jButton2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButton2);
        jToolBar1.add(jSeparator2);

        BotonModificarClase.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Iconos/008-doc_edit16x16.gif"))); // NOI18N
        BotonModificarClase.setText("Modificar");
        BotonModificarClase.setBorder(null);
        BotonModificarClase.setFocusable(false);
        BotonModificarClase.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        BotonModificarClase.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        BotonModificarClase.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BotonModificarClaseActionPerformed(evt);
            }
        });
        jToolBar1.add(BotonModificarClase);
        jToolBar1.add(jSeparator4);

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Iconos/New Folder_16x16-32.gif"))); // NOI18N
        jButton4.setText("Ver Detalle");
        jButton4.setBorder(null);
        jButton4.setFocusable(false);
        jButton4.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jButton4.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButton4);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Listar Clases por:"));

        chec_clasesExistentes.setText("Clases Existentes");
        chec_clasesExistentes.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                chec_clasesExistentesItemStateChanged(evt);
            }
        });

        chec_clasesAGenerar.setText("Clases A Generar");
        chec_clasesAGenerar.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                chec_clasesAGenerarItemStateChanged(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(39, Short.MAX_VALUE)
                .addComponent(chec_clasesExistentes)
                .addGap(18, 18, 18)
                .addComponent(chec_clasesAGenerar)
                .addGap(38, 38, 38))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(chec_clasesExistentes)
                    .addComponent(chec_clasesAGenerar))
                .addContainerGap(2, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 416, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(77, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(167, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 396, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 267, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void chec_clasesExistentesItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_chec_clasesExistentesItemStateChanged
     
        if(chec_clasesExistentes.isSelected()){
          AgregarClasesExistentesAModelo();
      }else if(!chec_clasesExistentes.isSelected()){modelo.clear();}
    }//GEN-LAST:event_chec_clasesExistentesItemStateChanged

    private void chec_clasesAGenerarItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_chec_clasesAGenerarItemStateChanged
        if(chec_clasesAGenerar.isSelected()){
         agregarClasesACrearAModelo();
      }else if(!chec_clasesAGenerar.isSelected()){modelo.clear();
      }
    }//GEN-LAST:event_chec_clasesAGenerarItemStateChanged

    private void BotonModificarClaseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotonModificarClaseActionPerformed
      
          Clase c=(Clase)Lista_de_Clases_Crear.getSelectedValue();
          if(c.getIdentificadordeClase()!=1){
          System.out.println(c.isEstado());
          panelIndex.getInstancia().mostrarClaseAModificar(c);
          }else MensajesAMostrar.mensajedeAdvertencia("Esta Clase Ya fue Generada");
          
          c=null;
    }//GEN-LAST:event_BotonModificarClaseActionPerformed

    
    /**
    * @param args the command line arguments
    */
  

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BotonModificarClase;
    private javax.swing.JList Lista_de_Clases_Crear;
    private javax.swing.JCheckBox chec_clasesAGenerar;
    private javax.swing.JCheckBox chec_clasesExistentes;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JToolBar.Separator jSeparator2;
    private javax.swing.JToolBar.Separator jSeparator3;
    private javax.swing.JToolBar.Separator jSeparator4;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JToolBar jToolBar1;
    // End of variables declaration//GEN-END:variables

}
